﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Helpers;
using DevExpress.UserSkins;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraReports.UI;
using DevExpress.XtraTreeList.Menu;


namespace QLNSClient
{
    public partial class FrmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        QLNSServiceReference.QLNSServiceClient sv = new QLNSServiceReference.QLNSServiceClient();

        bool isTreeListFocused = false;
        public int focusedNodeID;
        public int focusedLevel;
        public int focusedGrid;
        string columnID = "Đại học Trà Vinh";
        string columnID2 = "id";
        QLNSServiceReference.QLNSServiceClient client;
        DataTable phongBan;
        bool expandAllState = false;
        List<string> list;
        bool checkExpand = false;
        Int16 checkLevel = -1;


        public FrmMain()
        {
            InitializeComponent();
            client = new QLNSServiceReference.QLNSServiceClient();
            list = new List<string>();
            InitSkinGallery();
        }


        void InitSkinGallery()
        {
            //SkinHelper.InitSkinGallery(rgbiSkins, true);

        }

        #region XU LY TREELIST---------------------------

        private void loadDatabase()
        {
            try
            {
                phongBan = new DataTable();
                foreach (QLNSServiceReference.DONVI_HANHCHINH str in client.getDVHC())
                {
                    DataRow dr = phongBan.NewRow();
                    dr[0] = str.Ma_DV_HC;
                    dr[1] = str.TenDVHC;
                    phongBan.Rows.Add(dr);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi từ phía Server, không thể Load dữ liệu Đơn vị. " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        /// Create Child Of Node
        /// </summary>
        /// <param name="node"></param>
        void checkNodeExpand()
        {
            int level = trPhongBan.FocusedNode.Level;
            string checkList = null;
            if (level == 0)
                checkList = trPhongBan.FocusedNode.GetDisplayText(columnID);
            else if (level == 1)
                checkList = trPhongBan.FocusedNode.GetDisplayText(columnID) + trPhongBan.FocusedNode.ParentNode.GetDisplayText(columnID);
            else if (level == 2)
                checkList = trPhongBan.FocusedNode.GetDisplayText(columnID) + trPhongBan.FocusedNode.ParentNode.GetDisplayText(columnID) + trPhongBan.FocusedNode.ParentNode.ParentNode.GetDisplayText(columnID);

            foreach (string ls in list)
            {
                if (ls.Contains(checkList))
                {
                    checkExpand = true;
                    return;
                }
            }

        }

        private void taoNodeCon(int level)
        {
            //kiểm tra xem node đã đc expand hay chưa? nếu đã expand rồi thì không cần tạo lại node con
            gridView1.Columns.Clear();
            gv_Main.DataSource = null;
            string checkList = null;
            if (level == 0)
                checkList = trPhongBan.FocusedNode.GetDisplayText(columnID);
            else if (level == 1)
                checkList = trPhongBan.FocusedNode.GetDisplayText(columnID) + trPhongBan.FocusedNode.ParentNode.GetDisplayText(columnID);
            else if (level == 2)
                checkList = trPhongBan.FocusedNode.GetDisplayText(columnID) + trPhongBan.FocusedNode.ParentNode.GetDisplayText(columnID) + trPhongBan.FocusedNode.ParentNode.ParentNode.GetDisplayText(columnID);

            foreach (string ls in list)
            {
                if (ls.Contains(checkList))
                {
                    return;
                }
            }
            //nếu chưa expand thì tạo node con
            list.Add(checkList);

            TreeListNode node = trPhongBan.FocusedNode;
            TreeListNode subTreelistnode = null;
            string[] subnodes = null;
            if (level == 0)
            {
                if ((bool)node.Tag)
                {
                    //gridView1.Columns.Clear();
                    DataTable dt = new DataTable();
                    dt.Columns.Add("MA_DVTT");
                    dt.Columns.Add("TEN_DVTT");
                    dt.Columns.Add("MA_DV");
                    QLNSServiceReference.DANHMUC_DONVI[] lst = client.getDVTT_DV(node.GetDisplayText(columnID2));
                    int count = lst.Length, i = 0;
                    subnodes = new string[count];
                    foreach (QLNSServiceReference.DANHMUC_DONVI str in lst)
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = str.Ma_DV;
                        dr[1] = str.TenDVTT;
                        dr[2] = str.Ma_DV_CQ;
                        dt.Rows.Add(dr);

                        subnodes[i] = dr[0].ToString() + "@" + dr[1].ToString() + "@" + dr[2].ToString();
                        i++;
                    }
                    gv_Main.DataSource = dt;
                    gridView1.BestFitColumns();
                }
            }
            else if (level == 1)
            {
                if ((bool)node.Tag)
                {
                    //gridView1.Columns.Clear();
                    try
                    {
                        DataSet ds = client.getCB_DV(node.GetDisplayText(columnID2));
                        int count = ds.Tables[0].Rows.Count, i = 0;
                        subnodes = new string[count];
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            subnodes[i] = dr[0].ToString() + "@" + dr[1].ToString() +"@"+ dr[2].ToString() + "@" + dr[3].ToString() + "@" + dr[4].ToString() + "@" + dr[5].ToString();

                            i++;
                        }
                        gv_Main.DataSource = ds.Tables[0];
                       gridView1.BestFitColumns();

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Lỗi Server không thể Load dữ liệu Cán bộ thuộc đơn vi " + node.GetDisplayText(columnID) + ". " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {

            }

            try
            {
                foreach (string s in subnodes)
                {
                    string[] ss = s.Split('@');
                    subTreelistnode = trPhongBan.AppendNode(new object[] { ss[1], ss[0] }, node);
                    //subTreelistnode.StateImageIndex = 1;
                    if (level == 0 || level == 1)
                    {

                        subTreelistnode.HasChildren = true;
                        subTreelistnode.Tag = true;

                    }
                    else
                    {
                        subTreelistnode.HasChildren = false;

                    }
                }

            }
            catch { }

        }
        #endregion---------------------------------------


        private void taoCot(TreeList tl)
        {
            tl.BeginUpdate();
            tl.Columns.Add();
            tl.Columns[0].Caption = columnID;
            tl.Columns[0].VisibleIndex = 0;
            tl.Columns.Add();
            tl.Columns[1].Caption = columnID2;
            tl.Columns[1].VisibleIndex = 1;
            tl.Columns[1].Visible = false;
            tl.EndUpdate();
        }


        //Tạo node cha cho treelist
        private void taoNodes(DataTable dta, TreeListNode pNode)
        {
            trPhongBan.BeginUnboundLoad();
            TreeListNode node = null;
            int i = 0;
            foreach (DataRow dr in dta.Rows)
            {

                node = trPhongBan.AppendNode(new object[] { dr[1].ToString(), dr[0].ToString() }, pNode);
                node.StateImageIndex = 0;
                string _namHoc = trPhongBan.Nodes[i].GetDisplayText(columnID2);

                node.HasChildren = true;
                if (node.HasChildren)
                {
                    node.Tag = true;
                }
                i++;
            }

            trPhongBan.EndUnboundLoad();
        }

        private void trPhongBan_Leave(object sender, EventArgs e)
        {
            isTreeListFocused = false;
            TreeList treeList = sender as TreeList;
            focusedNodeID = treeList.FocusedNode.Id;
            focusedLevel = treeList.FocusedNode.Level;
        }

        void displayRightPanel()
        {

            //splashScreenManager1.ShowWaitForm();
            //dockPanel3.Text = trlChuongTrinhDaoTao.FocusedNode.GetDisplayText(columnID);
            if (trPhongBan.FocusedNode.Level == 0)//Đơn vị
            {
                gridView1.Columns.Clear();
                gv_Main.DataSource = client.getDVTT_DV(trPhongBan.FocusedNode.GetDisplayText(columnID2));
                gridView1.OptionsView.ColumnAutoWidth = true;

                gridView1.Columns[0].Caption = "Mã đơn vị trực thuộc";
                gridView1.Columns[1].Caption = "Tên đơn vị trực thuộc";
                gridView1.Columns[2].Caption = "Mã đơn vị chủ quản";
                gridView1.Columns[3].Visible = false;
                gridView1.BestFitColumns();
            }
            else if (trPhongBan.FocusedNode.Level == 1)//Đơn vị trực thuộc
            {
                gridView1.Columns.Clear();

                DataSet ds = client.getCB_DV(trPhongBan.FocusedNode.GetDisplayText(columnID2));
                gv_Main.DataSource = ds.Tables[0];
                gridView1.Columns[0].Caption = "Mã cán bộ";
                gridView1.Columns[1].Caption = "Họ tên";
                gridView1.Columns[2].Caption = "Năm sinh";
                gridView1.Columns[3].Caption = "Giới tính";
                gridView1.Columns[4].Caption = "Quê quán";
                gridView1.Columns[5].Caption = "Mã đơn vị";
                gridView1.OptionsView.ColumnAutoWidth = true;
                gridView1.BestFitColumns();

            }

            gridView1.BestFitColumns();
        }



        private void trPhongBan_BeforeExpand(object sender, BeforeExpandEventArgs e)
        {
            focusedNodeID = trPhongBan.FocusedNode.Id;
            focusedLevel = trPhongBan.FocusedNode.Level;
            (sender as TreeList).FocusedNode = e.Node;
        }


        //int countclicktree = 0;
        private void trPhongBan_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("đã click");
          //  countclicktree = 1;
            gv_Main.Visible = true;

            isTreeListFocused = true;
            TreeList treeList = sender as TreeList;
            focusedNodeID = treeList.FocusedNode.Id;
            focusedLevel = treeList.FocusedNode.Level;
            displayRightPanel();
        }

        private void trPhongBan_AfterExpand(object sender, NodeEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            TreeListNode node = trPhongBan.FocusedNode;
            taoNodeCon(node.Level);
            splashScreenManager1.CloseWaitForm();
        }

        private void trPhongBan_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
        {
            checkExpand = false;
        }

        private void trPhongBan_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
        {
            if (e.Menu is TreeListNodeMenu)
            {
                if (trPhongBan.FocusedNode.Level == 0)
                {
                    e.Menu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Thêm đơn vị", themdonvi));
                }
                else if (trPhongBan.FocusedNode.Level == 1)
                {
                    e.Menu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Thêm đơn vị trực thuộc", themDonVi_TT));
                }
                else if (trPhongBan.FocusedNode.Level == 2)
                {
                    e.Menu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Thêm Cán bộ", themCanBo));
                }
            }
        }
        private void themdonvi(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_DVHC frm = new Frm_DVHC();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void themDonVi_TT(object sender, EventArgs e)
        {
            Frm_DVTT frmDVTT = new Frm_DVTT();
            splashScreenManager1.ShowWaitForm();
            frmDVTT.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void themCanBo(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_THEMCANBO frm = new Frm_THEMCANBO();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void trPhongBan_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e)
        {
            TreeList tree = sender as TreeList;
            if (e.Node == tree.FocusedNode)
            {
                e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
                Rectangle rect = new Rectangle(
                e.EditViewInfo.ContentRect.Left,
                e.EditViewInfo.ContentRect.Top,
                Convert.ToInt32(e.Graphics.MeasureString(e.CellText, e.Appearance.Font).Width + 1),
                Convert.ToInt32(e.Graphics.MeasureString(e.CellText, e.Appearance.Font).Height));
                if ((sender as Control).Focused)
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
                else
                    e.Graphics.FillRectangle(SystemBrushes.InactiveCaption, e.Bounds);
                e.Graphics.DrawString(e.CellText, e.Appearance.Font, SystemBrushes.HighlightText, rect);
                e.Handled = true;
            }
        }








        private void btn_dsCanbo_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void btn_dsNgachbacluong_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void btn_xemdsCanbo_ItemClick(object sender, ItemClickEventArgs e)
        {
            //pn_Main.Controls.Clear();
            //uc_dsCanbo dsCanbo = new uc_dsCanbo();
            //dsCanbo.Dock = System.Windows.Forms.DockStyle.Fill;
            //pn_Main.Controls.Add(dsCanbo);
        }

        //private void btn_themmoiCanbo_ItemClick(object sender, ItemClickEventArgs e)
        //{
           
        //}

        private void btn_dsKhenthuong_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void btn_ThemCB_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_THEMCANBO frm = new Frm_THEMCANBO();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem8_ItemClick(object sender, ItemClickEventArgs e)
        {
            //pn_Main.Controls.Clear();
            //uc_dsNgachbacluong dsNgacbacluong = new uc_dsNgachbacluong();
            //dsNgacbacluong.Dock = System.Windows.Forms.DockStyle.Fill;
            //pn_Main.Controls.Add(dsNgacbacluong);
        }

        private void btn_KT_KL_ItemClick(object sender, ItemClickEventArgs e)
        {
            pn_Main.Controls.Clear();
            uc_KhenthuongKyluat KhenthuongKyluat = new uc_KhenthuongKyluat();
            KhenthuongKyluat.Dock = System.Windows.Forms.DockStyle.Fill;
            pn_Main.Controls.Add(KhenthuongKyluat);
        }

        private void btn_Chucvu_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_CV frmChucvu = new Frm_CV();
            splashScreenManager1.ShowWaitForm();
            frmChucvu.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void btn_ThongKe_ItemClick(object sender, ItemClickEventArgs e)
        {
            pn_Main.Controls.Clear();
            uc_ThongKe thongke = new uc_ThongKe();
            thongke.Dock = DockStyle.Fill;
            pn_Main.Controls.Add(thongke);
        }

        private void barButtonItem7_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_DVTT frmDVTT = new Frm_DVTT();
            splashScreenManager1.ShowWaitForm();
            frmDVTT.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e)
        {
            pn_Main.Controls.Clear();
            uc_dsDanhmucDV dsDanhmucDonvi = new uc_dsDanhmucDV();
            dsDanhmucDonvi.Dock = DockStyle.Fill;
            pn_Main.Controls.Add(dsDanhmucDonvi);
        }

        private void barButtonItem10_ItemClick(object sender, ItemClickEventArgs e)
        {
            //spCtrl_NgachBacluong.Panel2.Controls.Clear();
            //uc_dsSaplenluong dsSaplenluong = new uc_dsSaplenluong();
            //dsSaplenluong.Dock = DockStyle.Fill;
            //spCtrl_NgachBacluong.Panel2.Controls.Add(dsSaplenluong);
            //pn_Main.Controls.Clear();
            //uc_dsNgachbacluong dsNgacbacluong = new uc_dsNgachbacluong();
            //dsNgacbacluong.Dock = System.Windows.Forms.DockStyle.Fill;
            //pn_Main.Controls.Add(dsNgacbacluong);
        }

        private void ribbon_Click(object sender, EventArgs e)
        {

        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //if (sv.countSSL() > 0)
            //{
            //    barButtonItem10.Enabled = true;
            //}
            //else
            //{
            //    barButtonItem10.Enabled = false;
            //}


                list.Clear();
                DataTable dt = new DataTable();
                dt.Columns.Add("MA_DV");
                dt.Columns.Add("TEN_DV");
                try
                {
                    foreach (QLNSServiceReference.DONVI_HANHCHINH str in client.getDVHC())
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = str.Ma_DV_HC;
                        dr[1] = str.TenDVHC;
                        dt.Rows.Add(dr);
                    }
                    taoCot(trPhongBan);
                    taoNodes(dt, null);
                    trPhongBan.OptionsView.EnableAppearanceOddRow = true;
                    trPhongBan.OptionsView.ShowIndicator = true;
                    trPhongBan.OptionsView.ShowHorzLines = false;
                    trPhongBan.OptionsView.ShowVertLines = true;
                    trPhongBan.OptionsView.ShowButtons = true;
                    trPhongBan.OptionsView.ShowRoot = true;
                    trPhongBan.OptionsView.ShowColumns = true;
                    trPhongBan.OptionsBehavior.Editable = false;

                    //filter option
                    trPhongBan.Columns[0].OptionsFilter.AutoFilterCondition = AutoFilterCondition.Like;
                    trPhongBan.Columns[0].FilterMode = DevExpress.XtraGrid.ColumnFilterMode.DisplayText;
                    trPhongBan.OptionsBehavior.EnableFiltering = true;
                    trPhongBan.OptionsView.ShowAutoFilterRow = true;
                    trPhongBan.OptionsFilter.FilterMode = FilterMode.Smart;
                    trPhongBan.BestFitColumns();
                    checkLevel = -1;
                    expandAllState = false;

                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi từ phía Server, không thể Load dữ liệu. " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Frm_LOGIN frm = new Frm_LOGIN();
                frm.ShowDialog();

        }

        private void barButtonItem13_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_PCKhac frmPCK = new Frm_PCKhac();
            splashScreenManager1.ShowWaitForm();
            frmPCK.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem11_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_PCGV frmPCGV = new Frm_PCGV();
            splashScreenManager1.ShowWaitForm();
            frmPCGV.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem12_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_PCTN frmPCTN = new Frm_PCTN();
            splashScreenManager1.ShowWaitForm();
            frmPCTN.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem14_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_PCKN frmPCKN = new Frm_PCKN();
            splashScreenManager1.ShowWaitForm();
            frmPCKN.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem15_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_PT frmPT = new Frm_PT();
            splashScreenManager1.ShowWaitForm();
            frmPT.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem18_ItemClick(object sender, ItemClickEventArgs e)
        {
           
            Frm_CBCV frmCBCV = new Frm_CBCV();
            splashScreenManager1.ShowWaitForm();
            frmCBCV.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem17_ItemClick(object sender, ItemClickEventArgs e)
        {
            //splashScreenManager1.ShowWaitForm();
            Frm_CBPCKN frmCBCVKN = new Frm_CBPCKN();
            
            frmCBCVKN.Show();
            //ssplashScreenManager1.CloseWaitForm();
        }

        private void pn_Main_Paint(object sender, PaintEventArgs e)
        {

        }

        private void barButtonItem16_ItemClick(object sender, ItemClickEventArgs e)
        {
            //Frm_CBPCTN frmCBPCTN = new Frm_CBPCTN();
            //splashScreenManager1.ShowWaitForm();
            //frmCBPCTN.Show();
            //splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem19_ItemClick(object sender, ItemClickEventArgs e)
        {
            Frm_DVHC frmDVHC = new Frm_DVHC();
            splashScreenManager1.ShowWaitForm();
            frmDVHC.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem20_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_SAPTANGTN frmSaptangTN = new Frm_SAPTANGTN();
            frmSaptangTN.Show();
            splashScreenManager1.CloseWaitForm();

        }

        public static string sendMa_CB_CBCV;
        public static string sendMa_CB_CBKN;
        public static string sendMa_CB_CBNL;
        public static bool isBLDauTien = false;
        
        private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
        {
            string macb = gridView1.GetFocusedRowCellDisplayText(gridView1.Columns[0]);

            {
                if (trPhongBan.FocusedNode.Level != 0)
                {
                    try
                    {
                        e.Menu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Quyết định chức vụ", qdCV));
                        sendMa_CB_CBCV = gridView1.GetFocusedRowCellDisplayText(gridView1.Columns[0]);
                        e.Menu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Quyết định kiêm nhiệm", qdKN));
                        sendMa_CB_CBKN = gridView1.GetFocusedRowCellDisplayText(gridView1.Columns[0]);

                        int kqCheckCBNL = sv.checkQDCBNL(macb);
                        isBLDauTien = true;
                        Frm_dsSAPTANGBACLUONG.isSapTangBL = false;
                        if (kqCheckCBNL != -1)
                        {
                            
                            e.Menu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Quyết định bậc lương", qdNBL));
                            sendMa_CB_CBNL = gridView1.GetFocusedRowCellDisplayText(gridView1.Columns[0]);
                            
                        }
                        
                    }
                    catch
                    {
                        MessageBox.Show("Bạn cần click vào dòng dữ liệu", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        public void LoadGrid()
        {
            DataSet ds = client.getCB_DV(trPhongBan.FocusedNode.GetDisplayText(columnID2));
            gv_Main.DataSource = ds.Tables[0];
        }

        private void qdNBL(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_CBNGACHLUONG frm = new Frm_CBNGACHLUONG();
            frm.updateDL = new Frm_CBNGACHLUONG.CapNhatDLCBNL(LoadGrid);
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void qdKN(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_CBPCKN frm = new Frm_CBPCKN();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void qdCV(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_CBCV frm = new Frm_CBCV();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem18_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_dsCoThamNien frm = new Frm_dsCoThamNien();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem24_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_dsBACLUONG frm = new Frm_dsBACLUONG();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem23_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_dsNGACHLUONG frm = new Frm_dsNGACHLUONG();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem25_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_dsHSL frm = new Frm_dsHSL();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem26_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_dsCBNL frm = new Frm_dsCBNL();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem27_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_dsSAPTANGBACLUONG frm = new Frm_dsSAPTANGBACLUONG();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            //DialogResult dr = MessageBox.Show("Bạn muốn thoát khỏi chương trình?!", "Cảnh báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            //if (dr == DialogResult.OK)
            //{

            //    Application.Exit();

            //}
        }

        private void barButtonItem21_ItemClick(object sender, ItemClickEventArgs e)
        {
            gv_Main.Visible = false;
            pn_Main.Visible = true;
        }

        private void bar_HelloName_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void barButtonItem17_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_TINHLUONG frm = new Frm_TINHLUONG();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        private void barButtonItem28_ItemClick(object sender, ItemClickEventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            Frm_LCB frm = new Frm_LCB();
            frm.Show();
            splashScreenManager1.CloseWaitForm();
        }

        
        
    }
}